-
-
Notifications
You must be signed in to change notification settings - Fork 197
feat: use runtime Gradle version during plugin AAR build #3731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…kage.json of the runtime instead of hardcoded ones
… specified in the package.json of the runtime instead of hardcoded ones
for (const dir of androidSourceSetDirectories) { | ||
const dirNameParts = dir.split(path.sep); | ||
// get only the last subdirectory of the entire path string. e.g. 'res', 'java', etc. | ||
const dirName = dirNameParts[dirNameParts.length - 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use path.dirname(path.dirname(dir))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after a further looking into that, it could be just path.basename(dir)
const includeGradleContent = this.$fs.readText(includeGradlePath); | ||
const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent); | ||
private replaceGradleVersion(pluginTempDir: string, version: string): void { | ||
const gradleVersion = version || "4.4"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4.4 can be extracted to constant
} | ||
private replaceGradleAndroidPluginVersion(buildGradlePath: string, version: string): void { | ||
const gradleAndroidPluginVersionPlaceholder = "{{runtimeAndroidPluginVersion}}"; | ||
const gradleAndroidPluginVersion = version || "3.1.2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can be extracted to constant - 3.1.2
const includeGradlePath = path.join(platformsAndroidDirPath, INCLUDE_GRADLE_NAME); | ||
if (this.$fs.exists(includeGradlePath)) { | ||
const includeGradleContent = this.$fs.readText(includeGradlePath); | ||
const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe compileDependencies
is a better name. It is not a good practice to have and
in the name.
androidManifestContent = this.$fs.readText(manifestFilePath); | ||
} catch (err) { | ||
throw new Error( | ||
`Failed to fs.readFileSync the manifest file located at ${manifestFilePath}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be nice to add the message from real error here.
`Failed to fs.readFileSync the manifest file located at ${manifestFilePath}`
Also use $errors.failWithoutHelp
try { | ||
this.$fs.writeFile(pathToTempAndroidManifest, updatedManifestContent); | ||
} catch (e) { | ||
throw new Error(`Failed to write the updated AndroidManifest in the new location - ${pathToTempAndroidManifest}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we can add the real error message to the output.
Use this.$errors.fail
const packageJsonGradle = packageData && packageData.gradle; | ||
let runtimeVersions: IRuntimeGradleVersions = null; | ||
if (packageJsonGradle && (packageJsonGradle.version || packageJsonGradle.android)) { | ||
runtimeVersions = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this line and initialize the variable when declaring it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its here as we want to return null in such cases
const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent); | ||
|
||
if (repositoriesAndDependenciesScopes.length > 0) { | ||
this.$fs.appendFile(buildGradlePath, "\n" + repositoriesAndDependenciesScopes.join("\n")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe EOL
is better than \n
this.$fs.copyFile(pathToBuiltAar, path.join(aarOutputDir, `${shortPluginName}.aar`)); | ||
} | ||
} catch (e) { | ||
throw new Error(`Failed to copy built aar to destination. ${e.message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add the real error message to the output.
lib/node-package-manager.ts
Outdated
@@ -123,7 +123,7 @@ export class NodePackageManager implements INodePackageManager { | |||
const url = `https://registry.npmjs.org/${packageName}`; | |||
this.$logger.trace(`Trying to get data from npm registry for package ${packageName}, url is: ${url}`); | |||
const responseData = (await this.$httpClient.httpRequest(url)).body; | |||
this.$logger.trace(`Successfully received data from npm registry for package ${packageName}. Response data is: ${responseData}`); | |||
this.$logger.trace(`Successfully received data from npm registry for package ${packageName}.`); | |||
const jsonData = JSON.parse(responseData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you delete response data from the log message? It is added here with debug purposes?
@@ -164,113 +169,157 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { | |||
*/ | |||
public async buildAar(options: IBuildOptions): Promise<boolean> { | |||
this.validateOptions(options); | |||
const manifestFilePath = this.getManifest(options.platformsAndroidDirPath); | |||
const androidSourceSetDirectories = this.getAndroidSourceDirectories(options.platformsAndroidDirPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe androidSourceDirectories
is a better name.
androidManifestContent = this.$fs.readText(manifestFilePath); | ||
} catch (err) { | ||
throw new Error( | ||
`Failed to fs.readFileSync the manifest file located at ${manifestFilePath}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this.$errors.fail
or this.$erros.failWithoutHelp
instead throw new Error
const includeGradleContent = this.$fs.readText(includeGradlePath); | ||
const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent); | ||
|
||
if (repositoriesAndDependenciesScopes.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repositoriesAndDependenciesScopes.length
is enough
throw new Error(`Failed to copy built aar to destination. ${e.message}`); | ||
} | ||
} else { | ||
throw new Error(`No built aar found at ${pathToBuiltAar}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.fail()
}; | ||
} | ||
|
||
function setupDI(options: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe createTestInjector
is a better name
run ci |
2 similar comments
run ci |
run ci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really great work!
@@ -33,5 +34,5 @@ interface IBuildAndroidPluginData { | |||
/** | |||
* Information about tools that will be used to build the plugin, for example compile SDK version, build tools version, etc. | |||
*/ | |||
androidToolsInfo: IAndroidToolsInfoData; | |||
androidToolsInfo?: IAndroidToolsInfoData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this is not mandatory anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using it in a single place and now it defaults to the old logic inside (this.$androidToolsInfo.getToolsInfo();)
run ci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!!
ad8fe7f
to
4f46b6a
Compare
4f46b6a
to
1a881a1
Compare
PR Checklist
Related to #3719